//
//  SC_PieChartMarkerView.m
//  SCCharts
//
//  Created by Yang on 11/11/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SC_PieChartMarkerView.h"


@implementation SC_PieChartMarkerView
@synthesize markerImage,titleLabel,countLabel,overLabel;
@synthesize button;
@synthesize buttonImage;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
		self.backgroundColor = [UIColor clearColor];
		markerImage = [[UIImageView alloc] initWithFrame:self.bounds];
		markerImage.backgroundColor = [UIColor clearColor];
		[self addSubview:markerImage];
		titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(47.0f, 5.0f, 128.0f, 21.0f)];
		titleLabel.backgroundColor = [UIColor clearColor];
		titleLabel.font = [UIFont boldSystemFontOfSize:17.0f];
		titleLabel.textColor = [UIColor colorWithRed:122.0f/255.0f green:142.0f/255.0f blue:180.0f/255.0f alpha:1.0f];
		[self addSubview:titleLabel];
		
		countLabel = [[UILabel alloc] initWithFrame:CGRectMake(47.0f, 25.0f, 128.0f, 21.0f)];
		countLabel.backgroundColor = [UIColor clearColor];
		countLabel.font = [UIFont boldSystemFontOfSize:17.0f];
		countLabel.textColor = [UIColor colorWithRed:122.0f/255.0f green:142.0f/255.0f blue:180.0f/255.0f alpha:1.0f];
		[self addSubview:countLabel];
		
		overLabel = [[UILabel alloc] initWithFrame:CGRectMake(47.0f, 46.0f, 128.0f, 21.0f)];
		overLabel.backgroundColor = [UIColor clearColor];
		overLabel.font = [UIFont boldSystemFontOfSize:17.0f];
		overLabel.textColor = [UIColor colorWithRed:219.0f/255.0f green:153.0f/255.0f blue:72.0f/255.0f alpha:1.0f];
		[self addSubview:overLabel];
		
		button = [UIButton buttonWithType:UIButtonTypeCustom];
		button.frame = CGRectMake(153.0f, 53.0f, 29.0f, 29.0f);
		//[button setImage:[UIImage imageNamedTK:@"SCCharts.bundle/ForPieChart/btn29x29"] forState:UIControlStateNormal];
		[self addSubview:button];
		
		direction = [[NSMutableString alloc] init];
		
        // Initialization code
    }
    return self;
}
- (void)setDirectionString:(NSString *)string {
	[direction setString:string];
	[self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
	float marginX, marginY;
	marginX = marginY = 0.0f;
	float centerMargin = 0.0f;
	if ([direction isEqualToString:@"UpLeft"]) {
		[direction setString:@"left182x82_2"];
		marginX = 25.0f;
		//marginY = 50.0f;
	}
	else if ([direction isEqualToString:@"UpRight"]) {
		[direction setString:@"right182x82_2"];
		marginX = -25.0f;
		//marginY = 50.0f;
		centerMargin = - 35.0f;
	} 
	else if ([direction isEqualToString:@"DownLeft"]) {
		[direction setString:@"left182x82"];
		marginX = 25.0f;
		//marginY = -50.0f;
	} 
	else if ([direction isEqualToString:@"DownRight"]) {
		[direction setString:@"left182x82"];
		marginX = -25.0f;
		//marginY = -50.0f;
		centerMargin = - 35.0f;
	} 
	button.center = CGPointMake(button.center.x + centerMargin, button.center.y);
	//buttonImage.center = button.center;
	titleLabel.center = CGPointMake(titleLabel.center.x + centerMargin, titleLabel.center.y);
	countLabel.center = CGPointMake(countLabel.center.x + centerMargin, countLabel.center.y);
	overLabel.center = CGPointMake(overLabel.center.x + centerMargin, overLabel.center.y);
	//markerImage.image = [UIImage imageNamedTK:[NSString stringWithFormat:@"SCCharts.bundle/ForPieChart/%@",direction]];
	self.center = CGPointMake(self.center.x + marginX, self.center.y + marginY);
	
}


- (void)dealloc {
    [super dealloc];
}


@end
